package com.cc8w.admin.controller;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

public class AdminBaseController {
	protected HttpServletRequest request=null;
	protected HttpServletResponse response=null;
	protected Model model=null;
	protected String path="";
	protected  String basePath = "";
	protected  String selvetPath = "";
	
	
	
	@ModelAttribute("attributeAdminInit")
	public void adminInit(HttpServletRequest request, HttpServletResponse response,Model model) {
		System.out.println("每次请求都执行AdminController");
		this.setRequest(request);
		this.setResponse(response);
		
		
    	//项目名称
    	this.path = request.getContextPath();
    	//项目网址加项目名称
		this.basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + this.path + "/";
        //请求地址的路径名
		this.selvetPath = request.getServletPath();
        model.addAttribute("APP_PATH", this.path);
        model.addAttribute("BASE_PATH", this.basePath);
        model.addAttribute("SELVET_PATH", this.selvetPath);
        
		this.setModel(model);	
		
		
	}
	
	public HttpServletRequest getRequest() {
		return request;
	}


	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}


	public HttpServletResponse getResponse() {
		return response;
	}


	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}


	public Model getModel() {
		return model;
	}


	public void setModel(Model model) {
		this.model = model;
	}
	
	public String jump(String page,HashMap<String,String> hm) {
		
		Iterator<Entry<String, String>> entries  = hm.entrySet().iterator();
		while(entries.hasNext()){
			
		    Entry<String, String> entry = entries.next();
		    String key = entry.getKey();
		    String value = entry.getValue();
		    System.out.println(key+":"+value);
		    this.model.addAttribute(key,value);
		}
		
		return page;
	}


	
	

}
